#! /bin/bash

# sort [options] [files...]

# -t, specify the field separator, often use with -k.
# -k, start with which field, after ',' specify the stop field.
# If field looks like "4.5", which means the fied 4, from its 
# 5th character.
echo "sort -t: -k1,1 /etc/passwd"
sort -t: -k1,1 /etc/passwd
echo ""

# -n means the type of field as decimal number(this will end 
# until first character which is not a number).-r means reverse
# the sort result.
echo "sort -t: -k3nr /etc/passwd"
sort -t: -k3nr /etc/passwd
echo ""

# First use field 4 for sort, if filed 4 is the same, then use
# field 3 to sort.
echo "sort -t: -k4n -k3n /etc/passwd"
sort -t: -k4n -k3n /etc/passwd
echo ""

# -u specifies only output one record with the same key.
echo "sort -t: -k4n -u /etc/passwd" 
sort -t: -k4n -u /etc/passwd
echo ""


